﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Palsta.Core.data;

namespace Palsta.Core.exp
{
    class ExpLogicalNode : ExpNode
    {
        public enum ExpLogicalType
        {
            And,
            Or
        }

        #region Members

        private ExpLogicalType op;
        private ExpNode lnode;
        private ExpNode rnode;

        #endregion

        #region Constructors

        #endregion

        #region Accessors

        public virtual ExpLogicalType OP
        {
            get
            {
                return this.op;
            }
            set
            {
                this.op = value;
            }
        }

        public virtual ExpNode LNode
        {
            get
            {
                return this.lnode;
            }
            set
            {
                this.lnode = value;
            }
        }

        public virtual ExpNode RNode
        {
            get
            {
                return this.rnode;
            }
            set
            {
                this.rnode = value;
            }
        }

        #endregion

        #region Methods

        public ExpNodeType GetNodeType()
        {
            return ExpNodeType.Logical;
        }

        public bool Test(DataDictionary data)
        {
            switch (this.op)
            {
                case ExpLogicalType.And:
                    return this.lnode.Test(data) && this.rnode.Test(data);
                case ExpLogicalType.Or:
                    return this.lnode.Test(data) || this.rnode.Test(data);
            }
            return false;

        }

        public Field GetValue(DataDictionary data)
        {
            BooleanField f = new BooleanField(this.Test(data));
            return f;
        }

        public FieldType GetFieldType(DataDictionary data)
        {
            return FieldType.Boolean;
        }


        public void SetLeftOperand(ExpNode n)
        {
            this.lnode = n;
        }

        public void SetRightOperand(ExpNode n)
        {
            this.rnode = n;
        }

        public void SetOperands(ExpNode left, ExpNode right)
        {
            this.lnode = left;
            this.rnode = right;
        }

        public void SetOp(ExpLogicalType type)
        {
            this.op = type;
        }

        public ExpNode getLeftOperand()
        {
            return this.lnode;
        }

        public ExpNode getRightOperand()
        {
            return this.rnode;
        }

        public ExpLogicalType getOperator()
        {
            return this.op;
        }

        #endregion

        #region Override Operators

        #endregion

        #region Static Methods

        #endregion


    }

}
